﻿using AfrikDotnetWebSite.Models;
using System;
using System.Linq;
using System.Web.Mvc;

namespace AfrikDotnetWebSite.Controllers
{
    public class JobsController : Controller
    {
        private AfrikDotnetContext db = new AfrikDotnetContext();

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }

        public ActionResult Index()
        {
            return View(db.Jobs.Where(j => j.ExpiresOn > DateTime.UtcNow).ToList());
        }

        public ActionResult Details(int id = 0)
        {
            Job job = db.Jobs.Where(j => j.ExpiresOn > DateTime.UtcNow && j.Id == id)
                             .FirstOrDefault();
            if (job == null)
            {
                return HttpNotFound();
            }
            return View(job);
        }
    }
}